#include "finger.h"

#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOption>
#include <iostream>

using namespace std;

 Finger::Finger()
     : color(0, 128, 0)
 {
    //keyInput.start();
    buffer.setSamplingRate(0.01);
    buffer.initialize();
    buffer.start();
							    
    startTimer(20);
    //this->setPos(300, 300);
 }

 QRectF Finger::boundingRect() const
 {
     qreal adjust = 0.5;
     return QRectF(-18 - adjust, -22 - adjust,
                   36 + adjust, 60 + adjust);
 }

 QPainterPath Finger::shape() const
 {
     QPainterPath path;
     path.addRect(-10, -20, 20, 40);
     return path;
 }

 void Finger::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
 {
     //finger shape
     painter->setBrush(color);
     painter->drawEllipse(0, 0, 60, 60);
 }

 void Finger::timerEvent(QTimerEvent *)
 {
     //Leer Buffer
     //double* desp = this->keyInput.desplazamiento();
    double despX = this->buffer.algoritmosX.getPosicion();
	double despY = this->buffer.algoritmosY.getPosicion();

	despX *= 50;
	despY *= 50;

    this->setPos(-despX, despY);
 }
